home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-11-01 | 4.3 KB | 146 lines | [TEXT/MPS ] |
- #include "TDemoDocument.h"
-
- const CStr255 kTheLineToPrint = "Another amazing MacApp program!";
-
- //----------------------------------------------------------------------------------------
- // TDemoDocument::Initialize:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
- pascal void TDemoDocument::Initialize()
- {
- inherited::Initialize();
- fLineCount = 0;
- fReportPrinter = nil;
- fLineCountText = nil;
- }
- //----------------------------------------------------------------------------------------
- // TDemoDocument::IDemoDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
- pascal void TDemoDocument::IDemoDocument(TFile* itsFile, OSType itsScrapType)
- {
- FailInfo fi;
-
- this->IFileBasedDocument(itsFile, itsScrapType);
-
- fSaveUserSelection = false; // Don't have one so there's nothing to save
-
- if(fi.Try()) {
- fReportPrinter = new TReportPrinter;
- fReportPrinter->IReportPrinter("\pmonaco", // Font
- normal, // Face
- 9, // Size
- 72, // Left margin
- 648, // Bottom Margin
- true); // do auto-FF
- fi.Success();
- }
- else {
- fReportPrinter = (TReportPrinter *)FreeIfObject(fReportPrinter);
- fi.ReSignal();
- }
- }
-
-
- //----------------------------------------------------------------------------------------
- // TDemoDocument::DoMakeViews:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal void TDemoDocument::DoMakeViews(Boolean /*forPrinting*/)
- {
- TWindow *aWindow;
- FailInfo fi;
-
- VOLATILE(aWindow);
-
- if(fi.Try()) {
- aWindow = gViewServer->NewTemplateWindow(kMainView, this);
- fLineCountText = (TNumberText *)aWindow->FindSubView(kNumberOfLines);
- fLineCountText->SetValue(fLineCount, true);
- fi.Success();
- }
- else {
- fLineCountText = (TNumberText *) FreeIfObject(fLineCountText);
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TDemoDocument::DoRead:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadFile
-
- pascal void TDemoDocument::DoRead(TFile* aFile, Boolean /*forPrinting*/)
- {
- // Read in the long number of lines we'll be printing
-
- long lineCount;
- long bytes = sizeof(long);
-
- aFile->ReadData(&lineCount, bytes);
- fLineCount = lineCount;
- }
- //----------------------------------------------------------------------------------------
- // TDemoDocument::DoWrite:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadFile
- pascal void TDemoDocument::DoWrite(TFile* aFile, Boolean /*makingCopy*/)
- {
- // First, get the current value from the view
-
- long lineCount = fLineCount = fLineCountText->GetValue();
- long bytes = sizeof(long);
-
- aFile->WriteData(&lineCount, bytes); // and whip it onto the disk
- }
-
- //----------------------------------------------------------------------------------------
- // TDemoDocument::DoMenuCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
- pascal void TDemoDocument::DoMenuCommand(CommandNumber aCommandNumber)
- {
- long lineCount;
-
- switch(aCommandNumber)
- {
- case cPageSetup:
- fReportPrinter->HandlePageSetup();
- break;
-
- case cPrint:
- lineCount = fLineCountText->GetValue(); // get current value
- fReportPrinter->SetDocumentName(fTitle);
- if(fReportPrinter->StartReport(aCommandNumber)) {
- fReportPrinter->PrintHeader();
-
- // Your code to feed lines to the report printer goes here
- // (or better yet, all this should be inside a command)
- // this little example just prints a bunch of lines, all the same
-
- for(long i=0;i<lineCount;i++)
- fReportPrinter->PrintALine(kTheLineToPrint, true);
-
- fReportPrinter->EndReport();
- }
- break;
-
- default:
- inherited::DoMenuCommand(aCommandNumber);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TDemoDocument::DoSetupMenus:
- //----------------------------------------------------------------------------------------
- #pragma segment MAEvtHandlerRes
- pascal void TDemoDocument::DoSetupMenus()
- {
- inherited::DoSetupMenus();
- Enable(cSave, true);
- Enable(cPageSetup, true);
- Enable(cPrint, true);
- }
-